package JZOffer;


// https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/?envType=study-plan&id=lcof&plan=lcof&plan_progress=xxj1ozje
// 反转链表
public class Day002_2 {
    public static ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode node = null;
        ListNode cur = head;
        ListNode curNext = cur.next;
        while (curNext != null) {
            curNext = cur.next;
            cur.next = node;
            node = cur;
            cur = curNext;
        }
        return node;
    }

    public static void main(String[] args) {
        MySingleList list = new MySingleList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.display(reverseList(list.head));
    }
}
